package com.yc.mvc.web;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.awt.*;

@RestController//相当于@Controller 的子类该类的所有方法的返回值会被转化成json 格式

@RequestMapping("path")
public class PathController {

    //
    @RequestMapping({"index", "/"})
    public ModelAndView index() {
        ModelAndView mav = new ModelAndView();
        //设置视图名 ：redirect 响应重定向，否则是请求转发
        mav.setViewName("redirect:../home.html");
        return mav;
    }

    @RequestMapping(path = "demo1", method = RequestMethod.GET)
    public String demo1() {
        return "demo1";
    }

    @RequestMapping(path = "demo2", method = RequestMethod.POST)
    public String demo2() {
        return "demo2";
    }

    @RequestMapping("demo3")
    public String demo3() {
        return "demo3";
    }

    ///////////////////请求参数限定///////////////////////
    @GetMapping(value = "demo4", params = "a")
    public String demo4() {
        return "demo4";
    }

    @GetMapping(value = "demo5", params = "b=1")
    public String demo5() {
        return "demo5";
    }

    @GetMapping(value = "demo6", params = "b!=1")
    public String demo6() {
        return "demo6";
    }

    /////////////头域参数限定/////////////
    @GetMapping(value = "demo7")
    public String demo7() {
        return "demo7";
    }

    ///////////请求体类型限定///////////
    @GetMapping(value = "demo8", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public String demo8() {
        return "demo8";
    }

    /////////////响应体类型设置//////////
    @GetMapping(value = "demo9", produces = MediaType.TEXT_HTML_VALUE + ";charset=utf-8")
    public String demo9() {
        return "<h1>demo9</h1>";
    }

    @GetMapping(value = "demo10", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
    public String demo10() {
        return "<h1>demo10</h1>";
    }
}
